#include <iostream>
using namespace std;
const int N = 110;
int n, m, res;
int g[N][N];
int dis[N][N];
int dx[] = { 0, 1, 0, -1 };
int dy[] = { 1, 0, -1, 0 };
int dfs(int u, int v) {
	if (dis[u][v] != -1) return dis[u][v];
	dis[u][v] = 1;
	for (int i = 0; i < 4; i++) {
		int x = dx[i] + u, y = dy[i] + v;
		if (x < 1 || x > n || y < 1 || y > n) continue;
		if (g[x][y] <= g[u][v]) continue;

		dis[u][v] = max(dis[u][v], dfs(x, y) + 1);

	}

	return dis[u][v];
}
int main() {
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cin >> g[i][j];
		}
	}
	int ma = -1e9;
	memset(dis, -1, sizeof dis);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
		{
			ma = max(ma, dfs(i, j));
		}
	cout << ma << endl;
	return 0;
}